package com.woniu.cms.goods.core.controller;


import com.woniu.cms.goods.core.dto.OutbillDto;
import com.woniu.cms.goods.core.entity.GoodsOutbill;
import com.woniu.cms.goods.core.entity.GoodsOutbillMaterial;
import com.woniu.cms.goods.core.service.IGoodsGetbillMaterialService;
import com.woniu.cms.goods.core.service.IGoodsOutbillService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 领料单表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-18
 */
@RestController
@Api(tags = "领料单模块")
@RequestMapping("/goods-outbill")
public class GoodsOutbillController {
    @Autowired
    private IGoodsGetbillMaterialService getbillMaterialService;
    @Autowired
    private IGoodsOutbillService outbillService;

    /*
    * 新增领料单
    * @outbill，领料单主表信息
    * @list，领料单材料明细页材料列表
    * */
    @PostMapping("insert")
    @ApiOperation("新增领料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outbillDto",value = "领料单主表信息，领料单材料明细页材料列表")
    })
    public Result addOutbill(@RequestBody OutbillDto outbillDto){
        GoodsOutbill outbill = outbillDto.getOutbill();
        List<GoodsOutbillMaterial> list = outbillDto.getList();
        Result result=outbillService.addOutbill(outbill,list);
        return result;
    }
    /*
     * 删除领料单
     * @id，领料单主表id
     * @status，提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）
     * */
    @ApiOperation("删除领料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "领料单主表id"),
            @ApiImplicitParam(name = "status",value = "提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）")
    })
    @DeleteMapping("delete")
    public Result deleteOutbill(Integer id,Integer status){
        Result result=outbillService.deleteOutbill(id,status);
        return result;
    }

    /*
     * 修改领料单
     * @outbill，领料单主表信息
     * @list，领料单材料明细页材料列表
     * */
    @PutMapping("update")
    @ApiOperation("修改领料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outbillDto",value = "领料单主表信息,领料单材料明细页材料列表")
    })
    public Result updateOutbill(@RequestBody OutbillDto outbillDto){
        GoodsOutbill outbill = outbillDto.getOutbill();
        List<GoodsOutbillMaterial> list = outbillDto.getList();
        Result result=outbillService.updateOutbill(outbill,list);
        return result;
    }
    /*
    * 提交领料单
    * @outbill，领料单主表信息
    * @list，领料单材料明细页材料列表
    * */
    @PutMapping("commit")
    @ApiOperation("提交领料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outbillDto",value = "领料单主表信息,领料单材料明细页材料列表")
    })
    public Result commitOutbill(@RequestBody OutbillDto outbillDto){
        GoodsOutbill outbill = outbillDto.getOutbill();
        List<GoodsOutbillMaterial> list = outbillDto.getList();
        Result result=outbillService.commitOutbill(outbill,list);
        return result;
    }
}

